home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 265 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  3.0 KB

  1. Path: fido.asd.sgi.com!austern
  2. From: clamage@Eng.Sun.COM (Steve Clamage)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: new T[0] and sizeof(T)
  5. Date: 05 Feb 1996 09:24:46 PST
  6. Organization: Sun Microsystems Inc., Mountain View, CA
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <4f078q$kbh@engnews1.Eng.Sun.COM>
  9. References: <1996Feb1.091641.4676@iiasa.ac.at> <4erovm$4hh@engnews1.Eng.Sun.COM> <4evjke$87h@mulga.cs.mu.OZ.AU>
  10. NNTP-Posting-Host: isolde.mti.sgi.com
  11. X-Original-Date: 3 Feb 1996 17:50:18 GMT
  12. X-Newsreader: NN version 6.5.0 #21 (NOV)
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBVAwUBMRY9aEy4NqrwXLNJAQF0PQIAwwACfEr0jqyRfvUU7lbmajedqPj9+dhL
  15.     VP9ap7SxCx0f9xZ6L2GyU4HqiVZSjHSFo3zgk3AbyAhArNre3AVsOw==
  16.     =z6z4
  17. Originator: austern@isolde.mti.sgi.com
  18.  
  19. fjh@munta.cs.mu.OZ.AU (Fergus Henderson) writes:
  20.  
  21. >clamage@Eng.Sun.COM (Steve Clamage) writes:
  22.  
  23. >>The expression "new T[0]" is invalid, but if you
  24. >>use a non-const expression for the count, it is OK if the value is zero.
  25.  
  26. >What makes you think that the expression `new T[0]' is invalid?
  27. >As I read the working paper, it seems perfectly legal, and the
  28. >three compilers I tried it on were all quite happy to accept it.
  29.  
  30. I now believe I was wrong, and "new T[0]" is valid. Here's the
  31. background, if anyone is interested.
  32.  
  33. A while back this question arose in another context and I studied
  34. the then-current draft very carefully. I came to the conclusion 
  35. that "new T[0]" violated some explicit requirements. (I don't
  36. remember which version of the draft that was, but that is
  37. moot anyway.) When the question came up this time, I checked the
  38. "New" section of the current draft (5.3.4) and found a sentence that
  39. says that the value of any constant-expression must be strictly
  40. positive.  In addition, the "Declarators" chapter of the draft has
  41. always said that an array type may be declared only if the number of
  42. elements is greater than zero.
  43.  
  44. So I assumed that my earlier analysis was correct.
  45.  
  46. Fergus posted an opinion that "new T[0]" was allowed, and I also
  47. received some private email on the subject, so I thought I should
  48. check more carefully. I re-read that paragraph and discovered
  49. the "strictly-positive" requirement doesn't apply to the first
  50. dimension of the array, but only to the second and subsequent
  51. dimensions. The first dimension must be non-negative.
  52.  
  53. Then I checked with two people who deal with these sorts of issues
  54. in the C++ Committee. One at first made the same argument I did,
  55. but agreed when I showed how it didn't apply. Both believed this
  56. subject had never been explicitly discussed.
  57.  
  58. We agreed that it was inconsistent to allow "new T[n]" when n==0
  59. (which has always been allowed) but not "new T[0]". There also don't
  60. seem to be any technical difficulties in allowing the expression.
  61. (The new-expression yields type T*, not T[0].)
  62.  
  63. --
  64. Steve Clamage, stephen.clamage@eng.sun.com
  65. ---
  66. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  67.   Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy is
  68.   in http://reality.sgi.com/employees/austern_mti/std-c++/policy.html. ]
  69.